package com.hospital.controller;


import com.hospital.dao.AdminDao;
import com.hospital.domain.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    AdminDao adminDao;

    @PostMapping("/login")
    public Result login(@RequestBody Admin admin, HttpSession session){
        System.out.println(admin);
        String accountNum = admin.getAccountNum();
        String pwd = admin.getPwd();
        Admin admin1 = adminDao.Login(accountNum,pwd);
        if(admin1 == null)return new Result(Code.GET_ERR,null,"error");
        else{
            session.setAttribute("adminAccountNum",admin1.getAccountNum());
            session.setAttribute("adminID",admin1.getAdminID());
            return new Result(Code.GET_OK,admin1,"success");
        }

    }
}
